package com.lunago.agent.controller;

import com.lunago.agent.constant.JsonResult;
import com.lunago.agent.jwt.JwtPayLoad;
import com.lunago.agent.pojo.entity.UserGems;
import com.lunago.agent.service.UserGemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/aichat")
public class UserGemsController {

    @Autowired
    private UserGemsService userGemsService;

    @PostMapping("/gems")
    public JsonResult gems(@AuthenticationPrincipal JwtPayLoad payload) {
        Long userId = payload.getUserId();
        // 通过userid, 查询用户的点数
        UserGems userGems = userGemsService.queryMyGems(userId);
        return JsonResult.ok(userGems);
    }

    @PostMapping("/share")
    public JsonResult share(@AuthenticationPrincipal JwtPayLoad payload) {
        Long userId = payload.getUserId();
        // 通过userid, 执行分享业务，查询当日分享次数
        int times = userGemsService.share(userId);
        return JsonResult.ok(times, "成功分享，最新点数："+times);
    }

    @PostMapping("/share-times")
    public JsonResult shareTimes(@AuthenticationPrincipal JwtPayLoad payload) {
        Long userId = payload.getUserId();
        // 通过userid, 执行分享业务，查询当日分享次数
        int times = userGemsService.queryShareTimesToday(userId);
        return JsonResult.ok(times);
    }


}
